Skip to content

[WEEK10] 이지현#47

Merged
sik9252 merged 2 commits into
mainfrom
sik9252
Apr 22, 2026
Merged

[WEEK10] 이지현#47
sik9252 merged 2 commits into
mainfrom
sik9252

Conversation

@sik9252
Copy link
Copy Markdown
Collaborator

@sik9252 sik9252 commented Apr 14, 2026

이렇게 풀었어요

1. 최솟값 만들기

  • 문제를 풀었어요.
  • 풀이 시간 : 10분

1) 복잡도 계산

시간 복잡도: O(n log n)

공간 복잡도: O(1)


2) 접근 아이디어

이 문제는 두 배열의 원소를 각각 한 번씩 사용해서 곱의 합이 최소가 되도록 만들어야 한다.
합을 최소로 만들려면 한쪽 배열의 가장 작은 값과 다른 쪽 배열의 가장 큰 값을 곱하는 방식으로 짝을 지어야 한다.

그래서 A 배열은 오름차순, B 배열은 내림차순으로 정렬한 뒤 같은 인덱스끼리 곱해서 모두 더했다.

2. 이진 변환 반복하기

  • 문제를 풀었어요.
  • 풀이 시간 : 10분

1) 복잡도 계산

시간 복잡도: O(n)

공간 복잡도: O(n)


2) 접근 아이디어

이 문제는 문자열 s가 "1"이 될 때까지 이진 변환을 반복하면서,
총 몇 번 변환했는지와 제거한 0의 개수를 구하는 문제이다.

반복할 때마다 먼저 문자열에서 0을 모두 제거하고, 제거 전후 길이 차이를 이용해 삭제된 0의 개수를 누적한다.
그다음 남은 문자열의 길이를 2진수 문자열로 바꾸고 다시 같은 과정을 반복한다.

replace(/0/g, "")를 사용해 0을 한 번에 제거했고, 기존 길이 - 제거 후 길이로 없어진 0의 개수를 계산했다.

Copy link
Copy Markdown
Member

@doitchuu doitchuu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

깔끔한 풀이라 이해가 쉽네요!
고생하셨습니다 👍

let zeroCount = 0;

while (s !== "1") {
const filtered = s.replace(/0/g, "");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaceAll로 0을 모두 제거하기보다 정규 표현식을 활용하는 방법도 좋네요!

Copy link
Copy Markdown
Collaborator

@raejun92 raejun92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저랑 풀이가 거의 똑같은 거 같아요!

let zeroCount = 0;

while (s !== "1") {
const filtered = s.replace(/0/g, "");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 정규식 오랜만에 보네요!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 정규식 이거 귀합니다! ㅋㅋㅋ

@doitchuu doitchuu requested a review from LeeBaeJin April 15, 2026 11:48
Copy link
Copy Markdown
Collaborator

@LeeBaeJin LeeBaeJin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

깔끔한 풀이였습니다! 수고많으셨어요~

@sik9252 sik9252 merged commit 13a8e41 into main Apr 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants